import sys

from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton


class MyWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.init_ui()

    def init_ui(self):
        layout = QVBoxLayout()

        btn1 = QPushButton("点我就好", self)
        btn1.resize(btn1.sizeHint())
        btn1.move(50, 50)
        btn1.clicked.connect(self.on_click)

        self.setGeometry(300, 300, 300, 200)
        self.setWindowTitle('按钮点击事件')
        self.show()

        layout.addWidget(btn1)
        self.setLayout(layout)

    # 定义槽函数
    def on_click(self):
        print("按钮已经被点击")

if __name__ == '__main__':
    app = QApplication(sys.argv)
    w = MyWindow()
    w.show()
    sys.exit(app.exec_())
